<template>
	<view class="item-main" style="margin-bottom: 20rpx;">
	<!-- 	<view class="item-top">
			<text class='left'>{{ item.title }}</text>
		
			<view class="acea-row">
				<template v-if="item.isReward==2">
					<span class='right' @click="publish " style="margin-right: 3px;">发布悬赏</span>
				</template>
				<template v-else>
					<span class='right' @click="publish" style="margin-right: 3px;">修改悬赏</span>
					<template v-if="item.rewardStatus == 1">
						<span class='right' @click="setReward(0)" style="margin-right: 3px;">打开悬赏</span>
						<span class='right' v-if="item.trusteeship !='1'" @click="deleteReward"
							style="margin-right: 3px;">删除悬赏</span>
					</template>
					<template v-else>
						<span class='right' @click="setReward(1)" style="margin-right: 3px;">关闭悬赏</span>
					</template>
				</template>
				<span class='right rt' @click="tgMeth(item.rewardId)"
					v-if="item.type == 0&&item.isReward == '1' &&item.trusteeship !='1'">立即托管</span>
			</view>

		</view> -->
		<rewaredComp :item="item" :rewardType="item.type==0?3:7" @tgMeth="rewardId=>$emit('tgMeth',rewardId)" @updateItem ="(k,v)=>$emit('updateItem', k, v)" />
		<view class="item-center"
			@click="toPage(item.type == 0 ? '/pages/details/recruitWorkers/recruitWorkers?id=' + item.id :  '/pages/details/jobHunting/jobHunting?id=' + item.id )">
			<view class="acea-row row-middle info" v-if="item.type == 0">
				<image class='item-img' :src="item.images?item.images:noImageShow" mode="aspectFill"></image>
				<view class="content-main">
					<view class="line1 break acea-row">
						<text class="limit">店铺名称：{{ item.storeName ||''}} </text>
						<!-- <text class="red status">{{ item.adutStatus == 0 ? '待审核' : item.adutStatus == 1 ? '审核通过' : '驳回'}}</text> -->
					</view>
					<view class="line">招聘人数：{{ item.number || 0 }}人</view>
					<view class="line">薪资待遇：{{ item.salary || 0 }}K</view>
					<view class="line">经验要求：{{ item.experience }}年</view>
				</view>
			</view>
			<view class="acea-row row-middle info" v-else>
				<view class="content-main">
					<view class="line1 break acea-row">
						<!--<text 
							class="red status">{{ item.adutStatus == 0 ? '待审核' : item.adutStatus == 1 ? '审核通过' : '驳回'}}</text>
						-->
					</view>
					<view class="line">期望职位：{{ item.jobName || '' }}</view>
					<view class="line">期望薪资：{{ item.salary || 0 }}K</view>
					<view class="line">工作经验：{{ item.workExperience }} 年</view>
				</view>
			</view>
		</view>
		<view class="item-bottom" v-if="isOpear">
			<view class="info">已为您匹配到{{item.matchingNum || 0}}人·浏览 {{ item.view || 0 }} ·咨询{{item.communication || 0}}
			</view>
			<view class="bottom-btn acea-row row-between">
				<text @click="item.sort != '1'?toTopping():null">{{item.sort == '1'?'已置顶':'置顶'}}</text>
				<text>群发</text>
				<text @click="toVip(item)" :class="item.isVip== 1?'vip':''">
					{{item.isVip == '1'?'VIP信息':'VIP'}}</text>
				<text @click="toVisitor">访客</text>
				<text
					@click="toPage(item.type == 0 ? '/pages/releases/merchantService/merchantService?categoryOn=6&item='+JSON.stringify(item): '/pages/releases/merchantService/merchantService?categoryOn=5&item='+JSON.stringify(item))">编辑</text>
				<text @click="setMeth">设置</text>
			</view>
		</view>
		<topping :show="linkShow" :link-id="linkId" :types="linkTypes" @close="linkShow=false"
			@opear="m=>toOpear(m,'top')" />
		<setting :show="setShow" @close="setShow=false" :item="settingItem" @opear="toOpear" ref="setting"
			@toChange="(k,v)=>settingItem[k]=v" />
	</view>
</template>

<script>
	import {
		toPage
	} from '@/filters/commFilter.js'
	import topping from '@/pages/releases/components/topping.vue'
	import setting from '@/pages/releases/components/setting.vue'
	import rewaredComp from './publishReward/index.vue'
	import {
		reardTrusteeship,
		closeReward,
		deleteReward
	} from '@/api/api.js'
	export default {
		components: {
			topping,
			setting,
			rewaredComp
		},
		props: {
			item: {
				type: Object,
				default:()=>({})
			},
			isOpear:{
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				linkShow: false,
				linkId: 0,
				linkTypes: '',
				setShow: false,
				noImageShow: this.$noImageShow,
				settingItem: {}
			}
		},
		methods: {
			toPage,
			publish() {
				this.item.st = this.item.type;
				this.item.type = this.item.type == 0 ? 3 : 7

				let item = JSON.stringify(this.item)
				wx.navigateTo({
					url: '/pages/releases/offeraRreward/offeraRreward?item=' + item
				})
			},
			toTopping() {
				this.linkId = this.item.id;
				this.linkTypes = this.item.type == 0 ? 'recruiting' : 'job';
				this.linkShow = true;
			},
			toVisitor() {
				this.item.vistype = this.item.type == 0 ? 5 : 10
				uni.navigateTo({
					url: "/pages/aboutUsers/aboutUsers/visitor?data=" + JSON.stringify(this.item)
				})
			},
			setReward(st) {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否' + (st == 1 ? '关闭' : '打开') + '当前悬赏',
					success: function(res) {
						if (res.confirm) {
							closeReward({
								id: that.item.rewardId,
								status: st
							}).then(res => {
								// that.item. 'rewardStatus' = st;
								that.$emit("updateItem", 'rewardStatus', st)
								that.$util.Tips({
									title: (st == 1 ? '关闭' : '打开') + '悬赏成功'
								})
								// that.item.rewardStatus = st;
							})
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});

			},
			deleteReward() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否删除当前悬赏',
					success: function(res) {
						if (res.confirm) {
							console.log("that.item.rewardId", that.item.rewardId)
							deleteReward(that.item.rewardId).then(res => {
								// that.item. 'rewardStatus' = st;
								that.$emit("updateItem", 'isReward', 2)
								that.$util.Tips({
									title: '删除悬赏成功'
								})
								// that.item.rewardStatus = st;
							})
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			},
			toVip(data) {
				this.settingItem = data;
				this.settingItem.vistype = this.item.type == 0 ? 5 : 10
				console.log("this.settingItem", this.settingItem)
				let that = this;
				let ti = data.isVip && data.isVip == 1 ? '取消' : '开启';
				let st = data.isVip && data.isVip == 1 ? 0 : 1;
				uni.showModal({
					title: '提示',
					content: '是否' + ti + '信息VIP',
					success(res) {
						if (res.confirm) {
							that.$refs.setting.settingVip(st)
						}
					}
				})
			},
			toOpear(message, key) {
				console.log("key",key)
				if (key && key == 'top') {
					item.sort = 1;
				}else if(key && key == 'key'){
					this.$emit("reload")
				}
				
				this.$util.Tips({
					title: message
				})
			},
			setMeth() {
				this.item.vistype = this.item.type == 0 ? 5 : 10
				this.settingItem = this.item;
				this.setShow = true
			},
			//托管方法
			tgMeth(id) {
				let that = this;
				console.log(id)
				uni.showModal({
					title: "提示",
					content: "是否立即托管",
					success(res) {
						if (res.confirm) {
							reardTrusteeship({
								id
							}).then(res => {
								if (res.code == 200) {
									that.$util.Tips({
										title: '托管成功'
									})
									setTimeout(() => {
										that.page = 1;
										that.initList();
									}, 1500)

								}
							}).catch(e => {
								that.$util.Tips({
									title: e
								}, {
									tab: 2,
									url: "/pages/users/user_money/index"
								})
							})
						}
					}

				})

			},
		}
	}
</script>

<style lang="scss">
	.vip {
		border: 1px solid red !important;
		color: red !important;
	}

	.break {
		word-break: break-all;
	}

	.red {
		color: #EE212D;
	}

	.col_A6 {
		color: #A6A6A6;
	}

	.font600 {
		font-weight: 600;
	}

	.item-main {
		padding-bottom: 36rpx;
		background-color: #ffffff;
		margin: 0rpx 28rpx;
		border-radius: 2rpx;
		padding: 0rpx 24rpx 0rpx 28rpx;

		.item-top {
			// margin: 0rpx 24rpx 0rpx 28rpx;
			border-bottom: 2rpx solid rgba(238, 238, 238, 1);
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 86rpx;

			.left {
				font-size: 30rpx;
				font-weight: 400;
				color: rgba(56, 56, 56, 1);
			}

			.right {
				border-radius: 10rpx;
				background-color: rgb(238, 33, 45);
				color: rgba(255, 255, 255, 1);
				font-size: 24rpx;
				width: 142rpx;
				height: 44rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.item-center {
			display: flex;
			justify-content: space-between;
			margin-top: 36rpx;
			padding-bottom: 40rpx;
			border-bottom: 2rpx solid rgba(238, 238, 238, 1);

			.info {
				position: relative;
				width: 100%;

				.item-img {
					width: 170rpx;
					height: 144rpx;
					border-radius: 10rpx;
					margin-right: 18rpx;
				}

				.content-main {
					flex: 1;
					font-size: 24rpx;
					font-weight: 400;
					line-height: 20px;
					color: rgba(128, 128, 128, 1);

					.line1 {
						position: relative;
					}
				}
			}

			span {
				font-size: 22rpx;
				font-weight: 400;
				color: rgba(238, 33, 45, 1);
			}
		}

		.item-bottom {
			.info {
				margin-top: 20rpx;
				font-size: 22rpx;
				font-weight: 400;
				line-height: 40rpx;
				color: rgba(166, 166, 166, 1);
			}

			.bottom-btn {
				padding-bottom: 36rpx;
				margin-top: 18rpx;

				text {
					font-size: 24rpx;
					color: rgba(128, 128, 128, 1);
					width: 90rpx;
					line-height: 44rpx;
					border-radius: 4rpx;
					border: 2rpx solid rgba(229, 229, 229, 1);
					display: flex;
					justify-content: center;
				}
			}
		}
	}

	.limit {
		overflow: hidden;
		max-width: 380rpx;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.status {
		position: absolute;
		right: 0;
		top: 0;
	}
</style>